package cn.itlaobing.dao;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;


/**
 * 2017年11月10日09:36:03
 * Created by xuaner on 2017/11/6.
 */
public class BaseDao {
    private static final String DB_URL="jdbc:mysql://localhost:3306/train?characterEncoding=utf8";
    private static final String DB_USER="root";
    private static final String DB_PASSWORD="root";
    private static final String DB_DRIVER="com.mysql.jdbc.Driver";
    private DataSource dataSource=null;
    /**
     * 创建连接池
     *
     * */
    protected DataSource getDataSource(){
        if(dataSource!=null){
            return dataSource;
        }
        DruidDataSource dataSource=new DruidDataSource();
        dataSource.setUrl(DB_URL);
        dataSource.setUsername(DB_USER);
        dataSource.setPassword(DB_PASSWORD);
        dataSource.setDriverClassName(DB_DRIVER);
        this.dataSource=dataSource;
        return dataSource;
    }
}